<!-- 修改 木遥（微信:  http://marsgis.cn/weixin.html ） -->
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="https://muyao1987.gitee.io/cdn/marsgis.cn/favicon/favicon.ico" />
    <title>KML/KMZ解析加载(转GeoJson方式) | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <script
      type="text/javascript"
      src="/lib/include-lib.js"
      libpath="/lib/"
      include="jquery,layer,toastr,font-awesome,bootstrap,layer,haoutil,ztree,mars3d"
    ></script>
    <link href="/css/style.css" rel="stylesheet" />

    <!-- KML/KMZ 转 GeoJSON 格式 -->
    <script src="/lib/kml/kml-geojson.js" type="text/javascript" ></script>
    <!-- Kml2JsonLayer图层封装 -->
    <script src="./Kml2JsonLayer.js" type="text/javascript" ></script>
  </head>

  <body class="dark">
    <div id="mars3dContainer" class="mars3d-container"></div>

    <div id="viewSL" class="infoview">
      示例：
      <input type="button" class="btn btn-primary" value="铁路" onclick="shoRailway()" />
      <input type="button" class="btn btn-primary" value="高速公路线" onclick="showExpressway()" />
      <input type="button" class="btn btn-primary" value="气象等值面" onclick="showMeteorological()" />

      <input type="button" class="btn btn-primary" value="国家GDP数据" onclick="showGDP()" />
      <input type="button" class="btn btn-primary" value="海上安全通告" onclick="showSafetyNotice()" />
    </div>

    <div class="infoview" style="overflow: auto; right: 5px; left: auto; top: 80px; max-height: 88%">
      <ul id="treeOverlays" class="ztree"></ul>
    </div>

    <script src="/js/common.js"></script>
    <script src="./map.js"></script>

    <script type="text/javascript">
      "use script" //开发环境建议开启严格模式

      //===========================树控件处理============================

      treeEvent.on("tree", (e) => {
        initTree(e.treeData)
      })

      let layersObj = {}

      function initTree(arr, nameColum = "name") {
        //初始化树
        let setting = {
          check: {
            enable: true
          },
          data: {
            simpleData: {
              enable: true
            }
          },
          callback: {
            onCheck: treeOverlays_onCheck,
            onClick: treeOverlays_onClick
          }
        }

        let zNodes = []
        let pnode = {
          id: -1,
          name: "全部",
          type: "group",
          open: false,
          checked: true,
          icon: "/lib/jquery/ztree/css/mars/images/folder.png"
        }
        zNodes.push(pnode)

        for (let i = 0, len = arr.length; i < len; i++) {
          let item = arr[i]
          let name = item[nameColum] || "未命名"

          let node = {
            id: i,
            pId: pnode.id,
            name: name,
            checked: true,
            icon: "/lib/jquery/ztree/css/mars/images/layer.png"
          }
          zNodes.push(node)

          layersObj[i] = item.graphic
        }

        $.fn.zTree.destroy()
        $.fn.zTree.init($("#treeOverlays"), setting, zNodes)
      }

      function treeOverlays_onCheck(e, treeId) {
        let zTree = $.fn.zTree.getZTreeObj(treeId)

        //获得所有改变check状态的节点
        let changedNodes = zTree.getChangeCheckedNodes()
        if (changedNodes) {
          for (let i = 0; i < changedNodes.length; i++) {
            let treeNode = changedNodes[i]
            treeNode.checkedOld = treeNode.checked
            let graphic = layersObj[treeNode.id]
            if (graphic == null) {
              continue
            }
            let show = treeNode.checked
            //处理图层显示隐藏
            graphic.show = show
          }
        }
      }

      function treeOverlays_onClick(event, treeId, treeNode) {
        let graphic = layersObj[treeNode.id]
        if (graphic == null) {
          return
        }
        flyToEntity(graphic)
      }
    </script>
  </body>
</html>
